package at.fhooe.mc.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Polygon;

import javax.swing.JPanel;

import at.fhooe.mc.data.DoorState;

public class JTrianglePanelSquare extends JPanel  {

    private DoorState open;
    private Integer targetFloor = 0;
    private int statusOfDoors=0;

    public void openCloseDoors(DoorState state, int newtargetFloor) {
    	open = state;
    	targetFloor = newtargetFloor;
        this.repaint();
    }

    public int getStatusOfDoorsIn(){

    	return statusOfDoors;

    }


protected void paintComponent(Graphics g) {

    super.paintComponent(g);

    Point p1 = new Point(0,0);
    Point p2 = new Point(100,0);
    Point p3 = new Point(100,100);
    Point p4 = new Point(0,100);

    int[] xs = { p1.x, p2.x, p3.x,p4.x };
    int[] ys = { p1.y, p2.y, p3.y,p4.y };
    Polygon square = new Polygon(xs, ys, xs.length);

    g.setColor(Color.lightGray);

    if(open == DoorState.CLOSED){
    	statusOfDoors = 0;
    	g.setColor(Color.lightGray);
    	g.fillPolygon(square);
    	g.setColor(Color.darkGray);
    	g.drawPolygon(square);
    	g.drawLine(50, 0, 50, 100);
    } else if(open == DoorState.OPEN){
    	statusOfDoors = 1;
    	g.setColor(Color.lightGray);

    	int[] xs1 = { 0, 10, 10,0 };
        int[] ys1 = { 0, 0, 100,100 };
        Polygon square1 = new Polygon(xs1, ys1, xs1.length);
        g.fillPolygon(square1);

        int[] xs2 = { 90, 100, 100,90 };
        int[] ys2 = { 0, 0, 100,100 };
        Polygon square2 = new Polygon(xs2, ys2, xs2.length);
        g.fillPolygon(square2);

        g.setColor(Color.darkGray);
        g.drawPolygon(square);
    	g.drawLine(10, 0, 10, 100);
    	g.drawLine(90, 0, 90, 100);
    }else if(open == DoorState.OPENING || open == DoorState.CLOSING){
    	statusOfDoors = 2;
    	g.setColor(Color.lightGray);

    	int[] xs1 = { 0, 25, 25,0 };
        int[] ys1 = { 0, 0, 100,100 };
        Polygon square1 = new Polygon(xs1, ys1, xs1.length);
        g.fillPolygon(square1);

        int[] xs2 = { 75, 100, 100,75 };
        int[] ys2 = { 0, 0, 100,100 };
        Polygon square2 = new Polygon(xs2, ys2, xs2.length);
        g.fillPolygon(square2);

        g.setColor(Color.darkGray);
        g.drawPolygon(square);
    	g.drawLine(25, 0, 25, 100);
    	g.drawLine(75, 0, 75, 100);
    }

    g.setFont(new Font("Helvetica", Font.PLAIN, 42));
    if(targetFloor == 10){
    	g.drawString(targetFloor.toString(), 28, 65);
    } else {
    	g.drawString(targetFloor.toString(), 40, 65);
    }
    }

}
